// 在main文件声明mod，在各个文件使用use访问
mod config;
mod controller;
mod middleware;
mod model;
mod route;
mod service;
mod state;
mod utils;

use dotenv::dotenv;
use route::init_apis;
use tracing::info;
use std::env::{self, set_var};
use tokio::net::TcpListener;
use config::db::get_db_pool;
use state::AppState;

#[tokio::main]
async fn main() {
    // 日志打印
    set_var("RUST_LOG", "debug,tower_http=trace");
    // 设置跟踪
    tracing_subscriber::fmt::init();
    // 初始化环境变量
    dotenv().ok();
    let app_state = AppState {
        db_pool: get_db_pool().await,
    };

    let addr = env::var("ADDR").expect("Not configured in .env");
    info!("http://{}", addr);
    let listener = TcpListener::bind(addr).await.unwrap();
    axum::serve(listener, init_apis(app_state)).await.unwrap();
}
